<?php

namespace app\common\repository\articleTag;

use think\Db;
use app\common\model\article\ArticleTag as ArticleTagModel;

class R
{
    public function __construct(
        ArticleTagModel $articleTagModel
    )
    {
        $this->articleTagModel = $articleTagModel;
    }

    public function getTag($cond)
    {
        return ArticleTagModel::where($cond)
            ->find();
    }

    public function getTags($cond)
    {
        return ArticleTagModel::where($cond)
            ->select();
    }

    public function getHotTags()
    {
        $cond = [];
        $cond[] = ['id', 'IN', function ($query) {
            $query->table('article_access_article_tag')
                ->alias('a')
                ->join('article b', 'b.id=a.article_id', 'LEFT')
                ->where('b.delete_time', 'null')
                ->distinct(true)
                ->field('a.article_tag_id as id');
        }];
        return ArticleTagModel::where($cond)
            ->where($cond)
            ->select();
    }
}
